import 'package:flutter/material.dart';

class childcomp extends StatefulWidget {
  const childcomp({super.key, required this.count, required this.updataCount});
  //定义属性接收父组件传函值
  final int count;
  //定义属性接收父组件传函数
  final Function(int) updataCount;

  @override
  State<childcomp> createState() => _childcompState();
}

class _childcompState extends State<childcomp> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 200,
      height: 100,
      color: Colors.red,
      child: Column(
        children: [
          Text('我是孙子组件,父传值:${widget.count}'),
          ElevatedButton(
              onPressed: () {
                widget.updataCount(widget.count + 2);
              },
              child: const Text('修改父组件的值'))
        ],
      ),
    );
  }
}
